package com.datang.petstore.service.impl;


import com.datang.petstore.entity.InformCause;
import com.datang.petstore.entity.InformCauseExample;
import com.datang.petstore.entity.PetMold;
import com.datang.petstore.generatemapper.InformCauseMapper;
import com.datang.petstore.service.InformCauseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/*
 * @auther 顶风少年
 * @mail dfsn19970313@foxmail.com
 * @date 2019-11-01 13:52
 * @notify 违规原因
 * @version 1.0
 */
@Service
public class InformCauseServiceImpl implements InformCauseService {

    @Autowired
    private InformCauseMapper informCauseMapper;

    /*
     * @author 顶风少年
     * @date 2019/11/19 17:04
     * @mail dfsn199703132038@foxmail.com
     * @throws
     * @param
     * @result java.util.List<com.datang.petstore.entity.InformCause>
     * @notify 获取举报原因
     * version 1.0
     */
    @Cacheable(value = "getAllInformCause",key="1")
    public List<InformCause> getAllInformCause() {
        InformCauseExample informCauseExample = new InformCauseExample();
        return informCauseMapper.selectByExample(informCauseExample);
    }


    /*
     * @author 顶风少年
     * @date 2019/11/19 17:04
     * @mail dfsn199703132038@foxmail.com
     * @throws
     * @param
     * @result java.util.List<com.datang.petstore.entity.InformCause>
     * @notify 添加举报原因
     * version 1.0
     */
    @CacheEvict(value = "getAllInformCause",key="1" )
    @Transactional
    public void addInformCause(InformCause informCause) {
        informCause.setDate(new Date());
        informCauseMapper.insert(informCause);
    }


    /*
     * @author 顶风少年
     * @date 2019/11/19 17:04
     * @mail dfsn199703132038@foxmail.com
     * @throws
     * @param
     * @result java.util.List<com.datang.petstore.entity.InformCause>
     * @notify 删除举报原因
     * version 1.0
     */
    @CacheEvict(value = "getAllInformCause",key="1" )
    @Transactional
    public void deleteInformCause(Integer id) {
        informCauseMapper.deleteByPrimaryKey(id);
    }

    /*
     * @author 顶风少年
     * @date 2019/11/19 17:04
     * @mail dfsn199703132038@foxmail.com
     * @throws
     * @param
     * @result java.util.List<com.datang.petstore.entity.InformCause>
     * @notify 更改举报原因
     * version 1.0
     */
    @CacheEvict(value = "getAllInformCause",key="1" )
    @Transactional
    public void updateInformCause(InformCause informCause) {
        informCause.setDate(new Date());
        informCauseMapper.updateByPrimaryKeySelective(informCause);
    }
}
